export const getInputs = () => [
	['Hello World'],
	['   fly me   to   the moon  '],
	// cSpell: disable-next-line
	['luffy is still joyboy'],
	['a'],
];

/**
 * **[58. 最后一个单词的长度](https://leetcode.cn/problems/length-of-last-word/)**
 *
 * 给你一个字符串 `s`，由若干单词组成，单词前后用一些空格字符隔开。返回字符串中 **最后一个** 单词的长度。
 * **单词** 是指仅由字母组成、不包含任何空格字符的最大子字符串。
 *
 * @param s
 * @returns
 */
export default function (s: string): number {
	const totalLength = s.length;
	let endSpaceIndex = totalLength - 1;
	while (endSpaceIndex > 0) {
		if (s[endSpaceIndex] === ' ') endSpaceIndex--;
		else break;
	}

	let lastWordStartIndex = endSpaceIndex;
	while (lastWordStartIndex >= 0) {
		if (s[lastWordStartIndex] === ' ') break;
		else lastWordStartIndex--;
	}

	return endSpaceIndex - lastWordStartIndex;
}
